package com.informationsystem.service.impl;

import com.informationsystem.dao.DownloadsDao;
import com.informationsystem.model.Downloads;
import com.informationsystem.service.DownloadsManager;
import com.informationsystem.service.impl.GenericManagerImpl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import javax.jws.WebService;

@Service("downloadsManager")
@WebService(serviceName = "DownloadsService", endpointInterface = "com.informationsystem.service.DownloadsManager")
public class DownloadsManagerImpl extends GenericManagerImpl<Downloads, Long> implements DownloadsManager {
    DownloadsDao downloadsDao;

    @Autowired
    public DownloadsManagerImpl(DownloadsDao downloadsDao) {
        super(downloadsDao);
        this.downloadsDao = downloadsDao;
    }
    
    @Override
   	public List getDownloadsList() {
   		List<Downloads> downloadsList = getAll();
   		Collections.sort(downloadsList, new PostDateDsc());
   		return downloadsList;
   	}
   	
   	private  class PostDateDsc implements  Comparator<Downloads>{
   		@Override
   		public int compare(Downloads o1, Downloads o2) {
   			return o2.getPostDate().compareTo(o1.getPostDate());
   		}
   	}
}